import Vue from 'vue'

const jnpf = require('./utils/jnpf').default
import define from '@/utils/define'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import './assets/scss/common.scss'

import '@/styles/index.scss' // global css
import './assets/scss/theme.scss' // 主题

import App from './App'
import store from './store'
import router from './router'

import i18n from './lang' // internationalization
import './permission' // permission control
import './utils/error-log' // error log
import { message } from './utils/message';

import * as filters from './filters' // global filters

// 自定义按钮权限指令
import permission from "@/directive/permission";
Vue.use(permission)

Vue.use(Element, {
  size: jnpf.storageGet('size') || 'small', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
// 批量引入组件
import components from './components'
Vue.use(components)

// 添加实例属性
Object.assign(Vue.prototype, {
  define: require('./utils/define'), // 常量
  jnpf, // 公共方法
  hlsz:jnpf,
  formValidate: require('./utils/formValidate').default, // 表单验证
  $message: message
})


window.__global_report_params = {}
window.__global_report_setParam = (key,value)=>{
  window.__global_report_params[key] = value
}
window.__global_report_delParam = (key)=>{
  delete window.__global_report_params[key]
}
/**
 * 注册全局function
 * @param {*} id 
 * @param {*} params = [{"key":"recordtime","value":"2022-10-01"},{"key":"org","value":"1111"}]
 */
window.__global_report_call = (id)=>{
  if(Array.isArray(window.reportIframeList)){
    debugger
    window.reportIframeList.forEach((item,i)=>{
      debugger
      if(item==id){
        const token = jnpf.storageGet('token')
        let url = `${define.report}/preview.html?id=${id}&token=${token}&from=menu`
        if(window.__global_report_params){
          for(let key in window.__global_report_params){
            let value = window.__global_report_params[key]
            if(key!=undefined&&value!=undefined){
              url+=`&${key}=${value}`
            }
          }
        }
        let iframeId = 'iframe_'+id
        let myiframe = document.getElementById(iframeId);
        // myiframe&&myiframe.contentWindow&&(myiframe.contentWindow.postMessage({url:url,origin:window.location.origin},"*"))
        myiframe&&(myiframe.src=url)

      }
    })
  }
}

// 全局注册过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

const vm = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
export default vm